package com.doraz.orb.structs;

import java.util.ArrayList;

public class SearchResult implements OrbObject {

	private String searchId;
	private int groupCount;
	private int itemCount;
	private ArrayList<OrbObject> results;
	
	/**
	 * A result from a search (or browse)
	 * 
	 * @param searchId
	 * @param itemCount
	 */
	public SearchResult(String searchId, int groupCount, int itemCount) {
		this.searchId = searchId;
		this.itemCount = itemCount;
		this.results = new ArrayList<OrbObject>();
	}
	
	@Override
	public int getObjectType() {
		return OrbObject.ORB_SEARCHRESULT;
	}
	
	/**
	 * Adds an object to the result
	 * 
	 * @param obj
	 */
	public void addObject(OrbObject obj) {
		results.add(obj);
	}
	
	/**
	 * Gets the results
	 * @return
	 */
	public ArrayList<OrbObject> getResults() {
		return results;
	}
	
	/**
	 * Sets the results
	 * 
	 * @param results the results to set
	 */
	public void setResults(ArrayList<OrbObject> results) {
		this.results = results;
	}

	/**
	 * Gets the Orb Items only
	 * 
	 * @return
	 */
	public ArrayList<OrbItem> getItemsOnly() {
		ArrayList<OrbItem> items = new ArrayList<OrbItem>();
		for(OrbObject obj: results) {
			if(obj.getObjectType() == OrbObject.ORB_ITEM) {
				items.add((OrbItem) obj);
			}
		}
		
		return items;
	}
	
	/**
	 * Gets groups only
	 * 
	 * @return
	 */
	public ArrayList<Group> getGroupsOnly() {
		ArrayList<Group> groups = new ArrayList<Group>();
		for(OrbObject obj: results) {
			if(obj.getObjectType() == OrbObject.ORB_GROUP) {
				groups.add((Group) obj);
			}
		}
		
		return groups;
	}

	/**
	 * @return the searchId
	 */
	public String getSearchId() {
		return searchId;
	}

	/**
	 * @param searchId the searchId to set
	 */
	public void setSearchId(String searchId) {
		this.searchId = searchId;
	}

	/**
	 * @return the groupCount
	 */
	public int getGroupCount() {
		return groupCount;
	}

	/**
	 * @param groupCount the groupCount to set
	 */
	public void setGroupCount(int groupCount) {
		this.groupCount = groupCount;
	}

	/**
	 * @return the itemCount
	 */
	public int getItemCount() {
		return itemCount;
	}

	/**
	 * @param itemCount the itemCount to set
	 */
	public void setItemCount(int itemCount) {
		this.itemCount = itemCount;
	}
	
	
}
